import { defineStore } from 'pinia';
import { RouteRecordRaw } from 'vue-router';

import { routes } from '@/router';
import { getFlatArr } from '@/utils/index';

export const useAuthStore = defineStore('authStore', () => {
    // 当前页面的 router name，用来做按钮权限筛选
    const routeName = ref<string>('');
    // 菜单权限列表
    const authMenuList = ref<RouteRecordRaw[]>([]);
    const setRouteName = (name: string) => {
        routeName.value = name;
    };
    // 扁平化之后的一维数组路由，主要用来添加动态路由
    const flatMenuListGet = computed(() => {
        return getFlatArr(authMenuList.value);
    });
    const getAuthMenuList = () => {
        authMenuList.value = routes;
    };
    return {
        routeName,
        authMenuList,
        setRouteName,
        flatMenuListGet,
        getAuthMenuList,
    };
});
